﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;

namespace lcs.Web.supply
{
    public partial class AddUserProject : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                DataSet ds = new lcs.BLL.user().GetList(" roles_id = 3 ");//物料员

                this.ddl_clyUser.DataSource = ds;
                this.ddl_clyUser.DataTextField = "user_name";
                this.ddl_clyUser.DataValueField = "user_id";
                this.ddl_clyUser.DataBind();

                this.ddl_clyUser.Items.Insert(0, new ListItem("---未选择---", "-1"));
            }

        }

        protected void btnSave_Click(object sender, EventArgs e)
        {
            if (!string.IsNullOrEmpty(this.txt_proName.Text) && ddl_clyUser.SelectedValue != "-1")
            {
                string proid = this.txt_proName.Text.Split('|')[1];
                string user_id = this.ddl_clyUser.SelectedValue;

                lcs.BLL.user_project upm = new BLL.user_project();

                DataSet ds_up = upm.GetList(" user_id="+ user_id + "  and materialinfo_proid = '"+ proid + "' ");

                if (ds_up.Tables[0].Rows.Count == 0)
                {
                    lcs.Model.user_project up = new Model.user_project();

                    up.materialinfo_proid = proid;
                    up.user_id = int.Parse(user_id);

                    if (upm.Add(up) > 0)
                    {
                        Maticsoft.Common.MessageBox.Show(this, "添加成功！");
                    }
                }
                else
                {
                    Maticsoft.Common.MessageBox.Show(this, "此条记录已添加！");
                }

               


            }
            else
            {
                Maticsoft.Common.MessageBox.Show(this, "请填写项目名称和选择材料员！");
            }
        }
    }
}